<template>
<div class="probe views-container">
    <div class="wlm-table">
        <div class="wlm-table-hearder-btn">
            <router-link tag="span" to="/merchant/probeAdd">
                <el-button size="small" type="primary">发布</el-button>
            </router-link>
        </div>
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="85px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="内容：">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.luck_title" placeholder="标题、发布人昵称" style="width:160px;"></el-input>
                    </el-form-item>
                    <el-form-item label="类型：">
                        <el-select v-model="tableFormatData.userTable.files.luck_mode" placeholder="请选择" style="width:200px;">
                            <el-option label="全部" value="">
                            </el-option>
                            <el-option label="图文" :value="1">
                            </el-option>
                            <el-option label="视频" :value="2">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="话题：">
                        <el-select v-model="tableFormatData.userTable.files.luck_mode" placeholder="请选择" style="width:200px;">
                            <el-option label="全部" value="">
                            </el-option>
                            <el-option label="按时间开奖" :value="1">
                            </el-option>
                            <el-option label="按人数开奖" :value="2">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-tabs v-model="tableFormatData.userTable.files.luck_state" type="card" @tab-click="filesSerch">
                <el-tab-pane label="最新发布" name="0"></el-tab-pane>
                <el-tab-pane label="后台排序" name="3"></el-tab-pane>
                <el-tab-pane label="热门" name="2"></el-tab-pane>
                <el-tab-pane label="审核" name="1"></el-tab-pane>
            </el-tabs>
            <probe-box ref="chooseFiles" :changeEvt="subData" :probeList="tableFormatData.userTable.tableData"></probe-box>
            <!-- <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column prop="date" label="活动名称"  min-width="60">
                    <template slot-scope="scope">
                        <span>{{scope.row.luck_title}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="活动时间"  min-width="80">
                    <template slot-scope="scope">
                        <p style="white-space: nowrap;">开始时间:{{scope.row.luck_time[0]*1000| parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</p>
                        <p style="white-space: nowrap;">结束时间:{{scope.row.luck_time[1]*1000| parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="活动状态"  min-width="45">
                    <template slot-scope="scope">
                        <span v-if="scope.row.luck_state==1">已开奖</span>
                        <span v-if="scope.row.luck_state==2">抽奖中</span>
                        <span v-if="scope.row.luck_state==3">未开奖</span>
                    </template>
                </el-table-column>
                <el-table-column label="开奖方式"  min-width="45">
                    <template slot-scope="scope">
                        <span v-if="scope.row.luck_mode==1">按时间开奖</span>
                        <span v-if="scope.row.luck_mode==2">按人数开奖</span>
                        <span v-if="scope.row.luck_mode==3">手动开奖</span>
                    </template>
                </el-table-column>
                <el-table-column label="中奖数"  min-width="45">
                    <template slot-scope="scope">
                        <span>{{scope.row.is_luck_count}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="抽奖人数"  min-width="45">
                    <template slot-scope="scope">
                        <span>{{scope.row.user_count}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" >
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <router-link class="wlm-text" tag="span" :to="{path:'/application/lotteryInfoList', query :{ luck_id:scope.row.luck_id}}">
                                <el-button type="text">抽奖用户</el-button>
                            </router-link>
                            <div v-if="scope.row.luck_state==2&&scope.row.luck_mode==3" class="btn-line"></div>
                            <el-button v-if="scope.row.luck_state==2&&scope.row.luck_mode==3" class="wlm-text" type="text" @click="luckOpen(scope.row.luck_id)">开奖</el-button>
                            <div class="btn-line"></div>
                            <router-link class="wlm-text" tag="span" :to="{path:'/application/lotteryAdd', query :{ luck_id:scope.row.luck_id}}">
                                <el-button type="text">编辑</el-button>
                            </router-link>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.luck_id)">删除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table> -->
            <div class="pagination-content flex-row flex-justify-e flex-align-c">
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  getShopList,
  delShopData,
  showShopData
} from '@/api/merchant'
import probeBox from '@/components/probeBox/index'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'Probe',
  components: {
    probeBox
  },
  data() {
    return {
    //   chooseFilesConfig: {
    //     type: ['audio'],
    //     model: 'normal',
    //     initList: [],
    //     file_type: 'audio',
    //     uploadConfig: {
    //       params: {
    //         mode: 'perm'
    //       }
    //     }
    //   },
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getShopList,
            delList: delShopData
          },
          tableData: [],
          files: {
            type: 10
          },
          change: {
            card_cancel: {
              key: 'card_cancel',
              api: showShopData
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    subData(file) {
      const { id, type, is_show } = file
      console.log(file)
      console.log(arguments)
      if (type === 'del') {
        this.delTableItem(id)
      } else if (type === 'change') {
        this.$confirm('确定通过商家的入驻申请?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          showShopData({ id: id, is_show: is_show }).then((response) => {
            const { data: { code, data, msg }} = response
            console.log(data)
            if (code === 1) {
              this.$message({
                type: 'success',
                message: '审核成功!'
              })
            } else {
              this.$message.error(msg)
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/views/channel/styles/source.scss";
</style>
